package com.crrcdt.url;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
 * @author lj on 2020/11/18.
 * @version 1.0
 */
public class UrlTest {
    public static void main(String[] args) throws IOException {
        //1、下载地址
        final URL url = new URL("https://u.y.qq.com/cgi-bin/musics.fcg?-=albuminfoCallback&g_tk=984167298&sign=zzapnasu3foue16b4e44bc1c79929a5ae7f41fb50ab6508&loginUin=1366625002&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq.json&needNewCode=0&data=%7B%22comm%22%3A%7B%22ct%22%3A24%2C%22cv%22%3A10000%7D%2C%22albumDetail%22%3A%7B%22module%22%3A%22music.musichallAlbum.AlbumInfoServer%22%2C%22method%22%3A%22GetAlbumDetail%22%2C%22param%22%3A%7B%22albumMid%22%3A%22000gXm2i12Y1ps%22%7D%7D%7D");
        //2、连接到这个资源http
        HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
        //3、处理得到的数据
        final FileOutputStream fileOutputStream = new FileOutputStream("musics.fcg");
        final InputStream inputStream = httpURLConnection.getInputStream();
        final byte[] buffer = new byte[1024];
        int len;
        while ((len = inputStream.read(buffer)) != -1){
            fileOutputStream.write(buffer,0,len);
        }
        fileOutputStream.close();
        inputStream.close();
        httpURLConnection.disconnect();

    }
}
